home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2014 August / PCgo_CD_2014-08.iso / nw.pak / Unnamed File 000848.txt < prev    next >
Encoding:
Text File  |  2012-12-14  |  2.6 KB  |  73 lines

  1. // Copyright (c) 2012 Intel Corp
  2. // Copyright (c) 2012 The Chromium Authors
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. //  in the Software without restriction, including without limitation the rights
  7. //  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
  8. // pies of the Software, and to permit persons to whom the Software is furnished
  9. //  to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in al
  12. // l copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
  15. // PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
  16. // S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  17. //  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
  18. // ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. //  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  
  21. var v8_util = process.binding('v8_util');
  22.  
  23. function Menu(option) {
  24.   if (typeof option != 'object')
  25.     option = { type: 'contextmenu' };
  26.  
  27.   if (option.type != 'contextmenu' && option.type != 'menubar')
  28.     throw new String('Invalid menu type: ' + option.type);
  29.  
  30.   this.type = option.type;
  31.   v8_util.setHiddenValue(this, 'items', []);
  32.   nw.allocateObject(this, option);
  33. }
  34. require('util').inherits(Menu, exports.Base);
  35.  
  36. Menu.prototype.__defineGetter__('items', function() {
  37.   return v8_util.getHiddenValue(this, 'items');
  38. });
  39.  
  40. Menu.prototype.__defineSetter__('items', function(val) {
  41.   throw new String('Menu.items is immutable');
  42. });
  43.  
  44. Menu.prototype.append = function(menu_item) {
  45.   if (v8_util.getConstructorName(menu_item) != 'MenuItem')
  46.     throw new String("Menu.append() requires a valid MenuItem");
  47.     
  48.   this.items.push(menu_item);
  49.   nw.callObjectMethod(this, 'Append', [ menu_item.id ]);
  50. };
  51.  
  52. Menu.prototype.insert = function(menu_item, i) {
  53.   this.items.splice(i, 0, menu_item);
  54.   nw.callObjectMethod(this, 'Insert', [ menu_item.id, i ]);
  55. }
  56.  
  57. Menu.prototype.remove = function(menu_item) {
  58.   var pos_hint = this.items.indexOf(menu_item);
  59.   nw.callObjectMethod(this, 'Remove', [ menu_item.id, pos_hint ]);
  60.   this.items.splice(pos_hint, 1);
  61. }
  62.  
  63. Menu.prototype.removeAt = function(i) {
  64.   nw.callObjectMethod(this, 'Remove', [ this.items[i].id, i ]);
  65.   this.items.splice(i, 1);
  66. }
  67.  
  68. Menu.prototype.popup = function(x, y) {
  69.   nw.callObjectMethod(this, 'Popup', [ x, y ]);
  70. }
  71.  
  72. exports.Menu = Menu;
  73.